package com.ruoyi.standingbook.toilet.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.standingbook.toilet.domain.bo.ToiletBo;
import com.ruoyi.standingbook.toilet.domain.vo.ToiletImgVo;
import com.ruoyi.standingbook.toilet.domain.vo.ToiletVo;
import com.ruoyi.standingbook.toilet.service.IToiletService;
import com.ruoyi.standingbook.toilet.service.impl.ToiletExcelService;
import com.ruoyi.standingbook.v2toilet.domain.vo.V2ToiletVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 市政公厕管养
 *
 * @author cc
 * @date 2023-04-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/standingbook/toilet")
public class ToiletController extends BaseController {

    private final IToiletService iToiletService;
    private final com.ruoyi.standingbook.v2toilet.service.IToiletService v2toiletService;
    private final ToiletExcelService toiletExcelService;

    /**
     * 查询市政公厕管养列表
     */
    @SaCheckPermission("standingbook:toilet:list")
    @GetMapping("/list")
    public TableDataInfo<ToiletVo> list(ToiletBo bo, PageQuery pageQuery) {
        return iToiletService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出市政公厕管养列表
     */
    @SaCheckPermission("standingbook:toilet:export")
    @Log(title = "市政公厕管养", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ToiletBo bo, HttpServletResponse response) {
        List<ToiletVo> list = iToiletService.queryList(bo);
        ExcelUtil.exportExcel(list, "市政公厕管养", ToiletVo.class, response);
    }

    /**
     * 导出市政公厕管养日报
     */
    @SaCheckPermission("standingbook:toilet:export")
    @Log(title = "市政公厕管养", businessType = BusinessType.EXPORT)
    @PostMapping("/exportDailyReport")
    public void exportDailyReport(ToiletBo bo, HttpServletResponse response) {
        toiletExcelService.exportDailyReport(bo,response);
    }

    /**
     * 获取市政公厕管养详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("standingbook:toilet:query")
    @GetMapping("/{id}")
    public R<ToiletVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iToiletService.queryById(id));
    }

    /**
     * 新增市政公厕管养
     */
    @SaCheckPermission("standingbook:toilet:add")
    @Log(title = "市政公厕管养", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ToiletBo bo) {
        return toAjax(iToiletService.insertByBo(bo));
    }

    /**
     * 修改市政公厕管养
     */
    @SaCheckPermission("standingbook:toilet:edit")
    @Log(title = "市政公厕管养", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ToiletBo bo) {
        return toAjax(iToiletService.updateByBo(bo));
    }

    /**
     * 删除市政公厕管养
     *
     * @param ids 主键串
     */
    @SaCheckPermission("standingbook:toilet:remove")
    @Log(title = "市政公厕管养", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iToiletService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    @SaIgnore()
    @GetMapping("/toiletByDate")
    public R<List<V2ToiletVo>> toiletByDate1(String date) {
        return R.ok(v2toiletService.queryListByDate(date));
    }

    @SaIgnore()
    @GetMapping("/toiletAfterPic")
    public R<List<ToiletImgVo>> toiletAfterPic(String date)  {
        return R.ok(iToiletService.getAfterPicByDate(date));
    }

    @SaIgnore()
    @GetMapping("/toiletBeforePic")
    public R<List<ToiletImgVo>> toiletBeforePic(String date)  {
        return R.ok(iToiletService.getBeforePicByDate(date));
    }
}
